package com.iknow.xmpp.service;

import android.os.RemoteCallbackList;
import android.os.RemoteException;
import com.iknow.util.Loger;
import com.iknow.xmpp.service.aidl.IPrivacyListListener;
import com.iknow.xmpp.service.aidl.IPrivacyListManager.Stub;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.PrivacyList;
import org.jivesoftware.smack.PrivacyListListener;
import org.jivesoftware.smack.PrivacyListManager;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.PrivacyItem;
import org.jivesoftware.smack.packet.PrivacyItem.Type;

public class PrivacyListManagerAdapter extends IPrivacyListManager.Stub
{
  public static final String TAG = "PrivacyListManagerAdapter";
  private final PrivacyListListenerAdapter mPrivacyListListener;
  private final RemoteCallbackList<IPrivacyListListener> mPrivacyListListeners = new RemoteCallbackList();
  private final PrivacyListManager mPrivacyListManager;

  public PrivacyListManagerAdapter(PrivacyListManager paramPrivacyListManager)
  {
    this.mPrivacyListListener = new PrivacyListListenerAdapter(this);
    this.mPrivacyListManager = paramPrivacyListManager;
    this.mPrivacyListManager.addListener(this.mPrivacyListListener);
  }

  private List<PrivacyListItem> tranformPrivacyItemsToPrivacyListItems(List<PrivacyItem> paramList)
  {
    ArrayList localArrayList = new ArrayList();
    int i = 0;
    while (true)
    {
      if (i >= paramList.size())
        return localArrayList;
      localArrayList.add(new PrivacyListItem(((PrivacyItem)paramList.get(i)).getType().ordinal(), ((PrivacyItem)paramList.get(i)).getValue()));
      ++i;
    }
  }

  private List<PrivacyItem> tranformPrivacyListItemsToPrivacyItems(List<PrivacyListItem> paramList)
  {
    ArrayList localArrayList = new ArrayList();
    PrivacyItem.Type[] arrayOfType = PrivacyItem.Type.values();
    int i = 0;
    while (true)
    {
      if (i >= paramList.size())
        return localArrayList;
      localArrayList.add(new PrivacyItem(arrayOfType[((PrivacyListItem)paramList.get(i)).getType()].name(), false, i));
      ++i;
    }
  }

  public void addPrivacyListListener(IPrivacyListListener paramIPrivacyListListener)
    throws RemoteException
  {
  }

  public void blockUser(String paramString1, String paramString2)
    throws RemoteException
  {
  }

  public void createPrivacyList(String paramString, List<PrivacyListItem> paramList)
    throws RemoteException
  {
    Loger.d("PrivacyListManagerAdapter", "BEGIN createPrivacyList.");
    try
    {
      ArrayList localArrayList = new ArrayList();
      PrivacyItem localPrivacyItem = new PrivacyItem(PrivacyItem.Type.subscription.name(), true, 2);
      localPrivacyItem.setValue("both");
      localArrayList.add(localPrivacyItem);
      this.mPrivacyListManager.createPrivacyList(paramString, localArrayList);
      Loger.d("PrivacyListManagerAdapter", "END createPrivacyList.");
      return;
    }
    catch (XMPPException localXMPPException)
    {
      Loger.e("PrivacyListManagerAdapter", localXMPPException.getMessage());
    }
  }

  public void declineActivePrivacyList()
    throws RemoteException
  {
    try
    {
      this.mPrivacyListManager.declineActiveList();
      return;
    }
    catch (XMPPException localXMPPException)
    {
      Loger.e("PrivacyListManagerAdapter", localXMPPException.getMessage());
    }
  }

  public void declineDefaultPrivacyList()
    throws RemoteException
  {
    try
    {
      this.mPrivacyListManager.declineDefaultList();
      return;
    }
    catch (XMPPException localXMPPException)
    {
      Loger.e("PrivacyListManagerAdapter", localXMPPException.getMessage());
    }
  }

  public void editPrivacyList(String paramString, List<PrivacyListItem> paramList)
    throws RemoteException
  {
    Loger.d("PrivacyListManagerAdapter", "BEGIN editPrivacyList.");
    try
    {
      this.mPrivacyListManager.updatePrivacyList(paramString, tranformPrivacyListItemsToPrivacyItems(paramList));
      Loger.d("PrivacyListManagerAdapter", "END editPrivacyList.");
      return;
    }
    catch (XMPPException localXMPPException)
    {
      Loger.e("PrivacyListManagerAdapter", localXMPPException.getMessage());
    }
  }

  public String getActivePrivacyList()
    throws RemoteException
  {
    String str1;
    String str2;
    try
    {
      str2 = this.mPrivacyListManager.getActiveList().toString();
      str1 = str2;
      return str1;
    }
    catch (XMPPException localXMPPException)
    {
      Loger.e("PrivacyListManagerAdapter", localXMPPException.getMessage());
      str1 = null;
    }
  }

  public List<String> getBlockedGroupsByList(String paramString)
    throws RemoteException
  {
    ArrayList localArrayList = new ArrayList();
    try
    {
      PrivacyItem localPrivacyItem;
      Iterator localIterator = this.mPrivacyListManager.getPrivacyList(paramString).getItems().iterator();
      do
      {
        if (!(localIterator.hasNext()))
          break label98:
        localPrivacyItem = (PrivacyItem)localIterator.next();
      }
      while ((!(localPrivacyItem.getType().equals(PrivacyItem.Type.group))) || (localPrivacyItem.isAllow()));
      label98: localArrayList.add(localPrivacyItem.getValue());
    }
    catch (XMPPException localXMPPException)
    {
      Loger.e("PrivacyListManagerAdapter", localXMPPException.getMessage());
      return localArrayList;
    }
  }

  public List<String> getBlockedUsersByList(String paramString)
    throws RemoteException
  {
    ArrayList localArrayList = new ArrayList();
    try
    {
      PrivacyItem localPrivacyItem;
      Iterator localIterator = this.mPrivacyListManager.getPrivacyList(paramString).getItems().iterator();
      do
      {
        if (!(localIterator.hasNext()))
          break label98:
        localPrivacyItem = (PrivacyItem)localIterator.next();
      }
      while ((!(localPrivacyItem.getType().equals(PrivacyItem.Type.jid))) || (localPrivacyItem.isAllow()));
      label98: localArrayList.add(localPrivacyItem.getValue());
    }
    catch (XMPPException localXMPPException)
    {
      Loger.e("PrivacyListManagerAdapter", localXMPPException.getMessage());
      return localArrayList;
    }
  }

  public String getDefaultPrivacyList()
    throws RemoteException
  {
    String str1;
    String str2;
    try
    {
      str2 = this.mPrivacyListManager.getDefaultList().toString();
      str1 = str2;
      return str1;
    }
    catch (XMPPException localXMPPException)
    {
      Loger.e("PrivacyListManagerAdapter", localXMPPException.getMessage());
      str1 = null;
    }
  }

  public List<String> getPrivacyLists()
    throws RemoteException
  {
    Loger.d("PrivacyListManagerAdapter", "BEGIN getPrivacyLists.");
    ArrayList localArrayList = new ArrayList();
    try
    {
      int i;
      PrivacyList[] arrayOfPrivacyList = this.mPrivacyListManager.getPrivacyLists();
      Loger.d("PrivacyListManagerAdapter", "> registeredPrivacyLists size: " + arrayOfPrivacyList.length);
      if (arrayOfPrivacyList.length > 0)
      {
        i = 0;
        int j = arrayOfPrivacyList.length;
        if (i < j)
          break label73;
      }
      Loger.d("PrivacyListManagerAdapter", "END getPrivacyLists.");
      return localArrayList;
      label73: localArrayList.add(arrayOfPrivacyList[i].toString());
      Loger.d("PrivacyListManagerAdapter", "> " + ((String)localArrayList.get(i)) + " added.");
      ++i;
    }
    catch (XMPPException localXMPPException)
    {
      while (true)
        Loger.e("PrivacyListManagerAdapter", localXMPPException.getMessage());
    }
  }

  public void removePrivacyList(String paramString)
    throws RemoteException
  {
    try
    {
      this.mPrivacyListManager.deletePrivacyList(paramString);
      return;
    }
    catch (XMPPException localXMPPException)
    {
      Loger.e("PrivacyListManagerAdapter", localXMPPException.getMessage());
    }
  }

  public void removePrivacyListListener(IPrivacyListListener paramIPrivacyListListener)
    throws RemoteException
  {
    if (paramIPrivacyListListener != null)
      this.mPrivacyListListeners.unregister(paramIPrivacyListListener);
  }

  public void setActivePrivacyList(String paramString)
    throws RemoteException
  {
    try
    {
      this.mPrivacyListManager.setActiveListName(paramString);
      return;
    }
    catch (XMPPException localXMPPException)
    {
      Loger.e("PrivacyListManagerAdapter", localXMPPException.getMessage());
    }
  }

  public void setDefaultPrivacyList(String paramString)
    throws RemoteException
  {
    try
    {
      this.mPrivacyListManager.setDefaultListName(paramString);
      return;
    }
    catch (XMPPException localXMPPException)
    {
      Loger.e("PrivacyListManagerAdapter", localXMPPException.getMessage());
    }
  }

  private class PrivacyListListenerAdapter
  implements PrivacyListListener
  {
    public void setPrivacyList(, List<PrivacyItem> paramList)
    {
      int i = PrivacyListManagerAdapter.access$0(this.this$0).beginBroadcast();
      if (i <= 0)
      {
        PrivacyListManagerAdapter.access$0(this.this$0).finishBroadcast();
        return;
      }
      try
      {
        ((IPrivacyListListener)PrivacyListManagerAdapter.access$0(this.this$0).getBroadcastItem(--i)).setPrivacyList(paramString, PrivacyListManagerAdapter.access$1(this.this$0, paramList));
      }
      catch (RemoteException localRemoteException)
      {
        Loger.w("PrivacyListManagerAdapter", localRemoteException.getMessage());
      }
    }

    public void updatedPrivacyList()
    {
      Loger.d("PrivacyListManagerAdapter", "BEGIN updatedPrivacyList.");
      int i = PrivacyListManagerAdapter.access$0(this.this$0).beginBroadcast();
      if (i <= 0)
      {
        PrivacyListManagerAdapter.access$0(this.this$0).finishBroadcast();
        Loger.d("PrivacyListManagerAdapter", "END updatedPrivacyList.");
        return;
      }
      try
      {
        ((IPrivacyListListener)PrivacyListManagerAdapter.access$0(this.this$0).getBroadcastItem(--i)).updatedPrivacyList(paramString);
      }
      catch (RemoteException localRemoteException)
      {
        Loger.w("PrivacyListManagerAdapter", localRemoteException.getMessage());
      }
    }
  }
}